package com.laicunba.ext.web.controller.console.sys;

import org.json.simple.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.laicunba.ext.web.controller.BaseController;
import com.laicunba.service.mq.ActiveMQService;
import com.laicunba.util.StringUtil;

@Controller
@RequestMapping(value = "/console/ext/sys")
public class SendJmsController extends BaseController {

	@Autowired
	private ActiveMQService activeMQService;

	@SuppressWarnings("unchecked")
	@ResponseBody
	@RequestMapping(value = "/sendJms.htm")
	public String sendJms(String type, String name, String msg) {
		JSONObject json = new JSONObject();

		if ("topic".equalsIgnoreCase(type)) {
			activeMQService.sendTopics(name, msg);
		} else {
			activeMQService.sendQueues(name, msg, StringUtil.genGUID());
		}
		json.put("code", "SUCCESS");
		return json.toJSONString();
	}
}
